#ifndef _zk_commapi_h_
#define _zk_commapi_h_

#include "protocmd.h"

#define COMMPRO_RS232 "RS232"
#define COMMPRO_RS232_LIB "plrscomm"
#define COMMPRO_RS485 "RS485"
#define COMMPRO_RS485_LIB "plrscomm"
#define COMMPRO_TCP "TCP"
#define COMMPRO_TCP_LIB "pltcpcomm"
#define COMMPRO_UDP "UDP"
#define COMMPRO_UDP_LIB "pludpcomm"
#define COMMPRO_BLUETOOTH "BLUETOOTH"
#define COMMPRO_BLUETOOTH_LIB "plbtcomm"

#define COMM_PARAM_QUIRK_DEBUG 0x1
typedef struct {
	UDK_U16 StartTag;	//协议开始标记
	UDK_U16 DestAddr;	//目标地址
	UDK_U16 EndTag;		//协议结束标记
	
	UDK_U16	Quirks;
	int TimeOutMS;		//超时，单位毫秒
	int PackageSize;	//每个命令发送数据的最大长度，包括命令头及校验码

	void *priv;		//通讯对象，用于存储通讯对象指针
}ST_COMM_PARAMS, *PST_COMM_PARAMS;


typedef UDK_HANDLE 
	(*ZKECOMM_INIT)(PST_COMM_PARAMS param,const char *Address, unsigned short Port, int Speed);
typedef UDK_BOOL
	(*ZKECOMM_CLOSE)(UDK_HANDLE Handle);
typedef int 
	(*ZKECOMM_SEND)(UDK_HANDLE Handle,  const char *Data, int Count);
typedef int 
	(*ZKECOMM_READ)(UDK_HANDLE Handle,  char *Data, int Count, int TimeOutMS);
typedef int
	(*ZKECOMM_SENDCMD)(UDK_HANDLE Handle,int Command,  char *Data, int Count,PSessionHeader pshd);
typedef int 
	(*ZKECOMM_READCMD)(UDK_HANDLE Handle,int *pCommand,  char *Data, int *Count, int TimeOutMS);
typedef int 
	(*ZKECOMM_TERMINALREAD)(UDK_HANDLE Handle);
typedef const char *
	(*ZKECOMM_NAME)(UDK_HANDLE Handle);
typedef int 
	(*ZKECOMM_FLUSH)(UDK_HANDLE Handle);
typedef int 
	(*ZKECOMM_ERROR)(UDK_HANDLE Handle);
typedef int 
	(*ZKECOMM_SENDATCMDTOMODEM)(UDK_HANDLE Handle,  char *Data, int Count);
typedef int 
	(*ZKECOMM_READATCMDFROMMODEM)(UDK_HANDLE Handle,  char *Data, int Count, int TimeOutMS);
//
//Callback API only used for stdsdk
//
typedef void 
	(*ZKECOMM_ReadCallBack)(UDK_HANDLE hComm, int DataType, int DataSize, char *DataBuffer);

typedef struct{
	const char* comm_prot;//interface name
	const char* comm_lib;//interface library name ,may include parent path name,null if static installed
	ZKECOMM_INIT comm_init;
	ZKECOMM_CLOSE comm_close;
	ZKECOMM_SEND comm_send;
	ZKECOMM_READ comm_read;
	ZKECOMM_TERMINALREAD comm_terminalread;
	ZKECOMM_NAME comm_name;	
	ZKECOMM_FLUSH comm_flush;
	ZKECOMM_SENDATCMDTOMODEM comm_send_at_to_modem;
	ZKECOMM_READATCMDFROMMODEM comm_read_at_from_modem;
	//following APIs are for pullsdk compatible feature
	ZKECOMM_ERROR comm_error;
	ZKECOMM_SENDCMD comm_sendcmd;
	ZKECOMM_READCMD comm_readcmd;
}ST_COMM_MODULE,*PST_COMM_MODULE;


int install_comm_module(PST_COMM_MODULE module);
int uninstall_comm_module(const char* comm_prot);
PST_COMM_MODULE find_comm_module_by_proto(const char* proto);
PST_COMM_MODULE find_comm_module_by_library(const char* library);
int free_comm_modules(void);


#endif
